package com.yuanxiao.config;

import com.yuanxiao.pojo.Order;
import com.yuanxiao.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class Receiver {
    @Autowired
    OrderService orderService;

    @RabbitHandler
    @RabbitListener(queues = "queue.order.dlx")
    public void receviceMessage(Order order) {
        Order orderById = orderService.getOrderById(order.getId());
        if("未付款".equals(orderById.getStatus())){
            System.out.println("死信队列接收到消息，" + order.id + "过期未支付，订单已取消");
            System.out.println(order.toString());

            orderService.setOrderCancelStatusById(order.id);
        }
    }
    }
